package com.yanqu.road.server.cmd.marriage;

import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.marriage.CrossGroupMarriageMgr;
import com.yanqu.road.server.manager.marriage.CrossUnionMarriageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_AGREE_UNION_MARRIAGE_TO_PARTNER_DEAL_RESP, desc = "跨服商会联姻到对方处理响应")
public class CrossUnionMarriageToPartnerDealResponeCmd extends CrossCommand {
    private int dealResult;
    private MarriageInfo marriageInfo;
    private MarriageInfo partnerMarriage;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg reqMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.parseFrom(packet.getBytes());
        dealResult = reqMsg.getRet();
        marriageInfo = MarriagePb.parseMarriageInfo(reqMsg.getApplyData());
        if(0 == dealResult){
            partnerMarriage = MarriagePb.parseMarriageInfo(reqMsg.getPartnerData());
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        if(0 == dealResult){
            CrossUnionMarriageMgr.agreeMarriageFinalDeal(partnerMarriage.getChildUid());
        }
        CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.Builder respMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.newBuilder();
        respMsg.setRet(dealResult);
        respMsg.setApplyData(MarriagePb.parseMarriageApplyTempMsg(marriageInfo));
        if(0 == dealResult){
            respMsg.setPartnerData(MarriagePb.parseMarriageApplyTempMsg(partnerMarriage));
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_UNION_MARRIAGE_AGREE_RESP, respMsg);
        MessageHelper.sendPacket(marriageInfo.getServerId(), marriageInfo.getUserId(), pbMsg);
    }

    @Override
    public void sendData() {

    }
}
